package com.tian.controller.manage;

import com.tian.pojo.vo.ReportManageVO;
import com.tian.pojo.vo.UserManageVO;
import com.tian.service.ReportService;
import com.tian.service.manage.ReportManageService;
import com.tian.utils.JSONResult;
import com.tian.utils.PagedGridResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("manage")
public class ReportManageController {

   @Autowired
   private ReportManageService reportManageService;



    @GetMapping("/queryReport")
    public JSONResult queryReport(
            @RequestParam Integer page,
            @RequestParam Integer pageSize){

        if (page==null){
            page=1;
        }
        if (pageSize==null){
            pageSize=10;
        }

        PagedGridResult gridResult = reportManageService.queryPagedReport(page,pageSize);

        return JSONResult.ok(gridResult);

    }

    @GetMapping("/getReportManageByUserName")
    public JSONResult getReportManageByUserName(@RequestParam String username){
        if (StringUtils.isBlank(username)){
            JSONResult.errorMsg("用户名不能为空");
        }
        List<ReportManageVO> reportManageVOList = reportManageService.getReportManageByUserName(username);
        return JSONResult.ok(reportManageVOList);
    }

    @GetMapping("/deleteReportManage")
    public JSONResult deleteReportManage(@RequestParam String reportId){
        if (StringUtils.isBlank(reportId)){
            return JSONResult.errorMsg("该投诉记录不存在");
        }

        reportManageService.deleteReport(reportId);
        return JSONResult.ok();
    }

    @GetMapping("/handleReportManage")
    public JSONResult handleReportManage(@RequestParam String reportId){
        if (StringUtils.isBlank(reportId)){
            return JSONResult.errorMsg("该投诉记录不存在");
        }

        reportManageService.handleReportManage(reportId);
        return JSONResult.ok();

    }


}
